package com.webwork.lims.transport.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.webwork.lims.transport.dao.CarsDao;
import com.webwork.lims.transport.dataobject.Car;
import com.webwork.lims.transport.service.CarsService;
import com.webwork.lims.util.Paging;

@Service
public class CarsServiceImpl implements CarsService {

	@Autowired
	private CarsDao carDao;

	@Override
	public List<Car> query(Car queryObj) {
		return this.query(queryObj, new Paging(0, 0));
	}

	@Override
	public int count(Car queryObj) {
		return carDao.count(queryObj);
	}

	@Override
	public List<Car> query(Car queryObj, Paging paging) {
		return carDao.query(queryObj, paging.getCurrPage(), paging.getPageSize());
	}

	@Override
	public Car get(String carNum) {
		Car queryObj = new Car();
		queryObj.setCarNum(carNum);
		List<Car> cars = this.query(queryObj);
		if (cars != null && cars.size() > 0) {
			if (cars.size() > 1) {
				System.out.println("存在不止一条记录!");
			} else {
				return cars.get(0);
			}
		} else {
			System.out.println("找不到该地区!");
		}
		return null;
	}

	@Override
	public void insert(Car car) {
		carDao.insert(car);
	}

	@Override
	public void update(Car car) {
		carDao.update(car);
	}

	@Override
	public void save(Car car) {
		if (this.get(car.getCarNum()) != null) {
			this.update(car);
		} else {
			this.insert(car);
		}
	}

	@Override
	public void delete(String carNum) {
		carDao.delete(carNum);
	}
	
}
